define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'product_apply/index' + location.search,
                    add_url: 'product_apply/add',
                    // edit_url: 'product_apply/edit',
                    del_url: 'product_apply/del',
                    multi_url: 'product_apply/multi',
                    import_url: 'product_apply/import',
                    table: 'product_apply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                commonSearch:false,
                showToggle:false,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'nickname', title: __('用户')},
                        {field: 'mobile', title: __('电话')},
                        {field: 'product', title: __('Product_ids'), operate: 'LIKE'},
                        {field: 'status', title: __('状态'),formatter:function (value) {
                            return value == 1 ? "<p style='color: #02f8c6;'>已设置</p>" : "默认" ;
                            }},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'detail',
                                title: __('设置'),
                                // text: __('收款信息'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'product_apply/detail',
                                hidden:function (row) {
                                    return row.status;
                                }
                            }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            Controller.api.bindevent();
            $(".deletes").click(function () {
                let _this = $(this);
                let name = _this.data("product");
                layer.confirm("确认不对产品【"+name+"】进行政策设置吗？",function (index) {
                    layer.close(index);
                    _this.parent().parent().parent().parent().remove();
                });
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
